package cn.edu.lingnan.service.impl;




import cn.edu.lingnan.mapper.StudentStatisticsMapper;
import cn.edu.lingnan.service.StudentStatisticsService;
import cn.edu.lingnan.user.pojos.PageBean;
import cn.edu.lingnan.user.vos.StudentStatisticsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class StudentStatisticsServiceImpl implements StudentStatisticsService {

    @Autowired
    private StudentStatisticsMapper studentStatisticsMapper;

    @Override
    public PageBean<StudentStatisticsVO> getStudentStatistics(Integer page, Integer pageSize) {
        // 计算偏移量
        Integer offset = (page - 1) * pageSize;

        // 查询分页数据
        List<StudentStatisticsVO> studentStatistics = studentStatisticsMapper.selectStudentStatistics(offset, pageSize);

        // 查询总数
        Integer total = studentStatisticsMapper.countStudentStatistics();

        // 封装分页结果
        PageBean<StudentStatisticsVO> pageBean = new PageBean<>();
        pageBean.setTotal(total);
        pageBean.setRows(studentStatistics);

        return pageBean;
    }
}
